Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting to tidy up mathics.core.pattern #1086

Merged
merged 8 commits into from
Sep 19, 2024
Merged

Starting to tidy up mathics.core.pattern #1086

merged 8 commits into from
Sep 19, 2024

Conversation

mmatera
Copy link
Contributor

@mmatera mmatera commented Sep 16, 2024

In line with the last changes proposed by @rocky, I was doing a pass over mathics.core.pattern and fixing some issues reported by the linter.

@@ -1,6 +1,11 @@
# cython: language_level=3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW - I think we should remove cython. At this point it is probably not speeding things up and getting in the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, Cython was useful in detecting some errors when I renamed some arguments. Maybe we can remove this later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - leave in then.

count += 1
return count

def sort(self):
"""Sot the elements according to their sort key"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sot the -> Sort

@rocky
Copy link
Member

rocky commented Sep 17, 2024

As I look over I see lots of opportunity for adding type annotations. But one step at a time. See comments and merge when you are satisfied.

Also consider making a pass over https://github.com/Mathics3/mathics-development-guide/blob/master/docs/extending/code-overview/pattern-matching.rst (but note that this section is going to be moved up a level out of "Extending" and its own section.

@mmatera
Copy link
Contributor Author

mmatera commented Sep 17, 2024

As I look over I see lots of opportunity for adding type annotations. But one step at a time. See comments and merge when you are satisfied.

Fist, I need to be sure about what are the parameters that the functions and methods are receiving. Also, one of the complaints of the linter is that many of these functions have too many parameters. Probably a first step would be to collect all these parameters into a dictionary or a tuple, and then establish the typing.

Also consider making a pass over https://github.com/Mathics3/mathics-development-guide/blob/master/docs/extending/code-overview/pattern-matching.rst (but note that this section is going to be moved up a level out of "Extending" and its own section.

OK

@rocky
Copy link
Member

rocky commented Sep 17, 2024

Something to think about: can we write py tests or unit tests for the pattern module that works in isolation; that is, it doesn't get tested via expression evaluation but instead is narrowed to patterns or even in some cases the specific methods of Pattern and its subclasses?

@rocky
Copy link
Member

rocky commented Sep 17, 2024

Concerning the https://github.com/Mathics3/mathics-core/actions/runs/10905508459/job/30264517603?pr=1086 failure, I suspect that various linters detect this too.

@rocky
Copy link
Member

rocky commented Sep 17, 2024

@mmatera When you think things are stable, let me know. I'd like to checkout this branch and look it over to see if this helps me understand how patterns work better. Thanks.

@mmatera
Copy link
Contributor Author

mmatera commented Sep 17, 2024

@mmatera When you think things are stable, let me know. I'd like to checkout this branch and look it over to see if this helps me understand how patterns work better. Thanks.

I am nearly to finish: I am trying to determine the right annotations using the errors reported by Cython. I'll let you when I finish

@mmatera
Copy link
Contributor Author

mmatera commented Sep 17, 2024

Something to think about: can we write py tests or unit tests for the pattern module that works in isolation; that is, it doesn't get tested via expression evaluation but instead is narrowed to patterns or even in some cases the specific methods of Pattern and its subclasses?

Yes, that would be ideal. The problem is that I still have some problems understanding what some parts of this code do. I hope these changes made it easier to investigate.

@mmatera
Copy link
Contributor Author

mmatera commented Sep 17, 2024

@rocky, I think this is ready now. In a next PR I will go over mathics.builtin.patterns.py doing the same.

@rocky
Copy link
Member

rocky commented Sep 17, 2024

@rocky, I think this is ready now. In a next PR I will go over mathics.builtin.patterns.py doing the same.

Thanks - give me another day or so to try this out.

Here are some minor things noticed in looking over this module. Pattern -> BasePattern; Pattern_ -> Pattern.
@rocky
Copy link
Member

rocky commented Sep 19, 2024

LGTM - let's merge and iterate. The developer docs and debugger will now need to track these changes.

@rocky rocky merged commit 77db22f into master Sep 19, 2024
11 checks passed
@rocky rocky deleted the tidyup_core_pattern branch September 19, 2024 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants