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

Optional arguments in environs implementation methods #741

Open
knutnergaard opened this issue Aug 14, 2024 · 13 comments
Open

Optional arguments in environs implementation methods #741

knutnergaard opened this issue Aug 14, 2024 · 13 comments

Comments

@knutnergaard
Copy link
Contributor

knutnergaard commented Aug 14, 2024

Ref. this post:

No, sorry for not bing clear. The kwargs is very logical. I'm alluding to name being optional in the public method, but not in the private one.

Ah. This is also intentional. There shouldn’t be any optional arguments in the environment implementation methods. I can’t swear that there aren’t some now, but my intention at the start was that everything arriving to the environment methods would be defined and of the correct type. This way, any type conversion and defaults are handled at the generic fontParts level and this behavior will thus be consistent across implementations. It also alleviates a ton of work in the subclasses because all the type testing and conversion is a lot of redundant code. I was looking to see if I had written any notes about this and I found this in the documentation that might be helpful.

Originally posted by @typesupply in #207 (comment)

There are indeed a few cases of default values in the environment implementation of methods. If desired, I can convert them to be absolute as I come across them while implementing the type annotation and working on the docs.

Also, when running mypy, there will be a conflict between the public and private methods whenever one employs optional values and the other does not. The best thing, unless you want to ignore this, is to implement a conditional to eliminate the possibility of None wherever it's incompatible. I can do this too if you wish.

@knutnergaard knutnergaard mentioned this issue Aug 16, 2024
@benkiel
Copy link
Member

benkiel commented Aug 21, 2024

Yes, please do both of these things!

@knutnergaard
Copy link
Contributor Author

@benkiel, the BaseGlyph class has a few cases where default None values in the environment implementation method are actually documented in the docstring (e.g., in the _appendGuideline method). Can you confirm that these also should be absolute?

@benkiel
Copy link
Member

benkiel commented Sep 19, 2024

Hey @knutnergaard I'm unsure what you mean by absolute in this context, could you elaborate?

@knutnergaard
Copy link
Contributor Author

knutnergaard commented Sep 19, 2024

Hey @knutnergaard I'm unsure what you mean by absolute in this context, could you elaborate?

@benkiel, sorry, absolute is probably not the right word. I simply mean mandatory or non-optional.

@benkiel
Copy link
Member

benkiel commented Sep 24, 2024

Yes, we should note the additional ones in the private method.

@knutnergaard
Copy link
Contributor Author

Yes, we should note the additional ones in the private method.

I'm not sure I understand, but I take it to mean that documented optional values, None or otherwise, are intentional, contrary to the general idea laied out by @typesupply in the OP, and should be kept as is?

@benkiel
Copy link
Member

benkiel commented Sep 25, 2024

Sorry, no; we should move those optional things up to the non-private method and document there. Sorry, I lost the thread on this; please do what Tal said and ignore me!

@knutnergaard
Copy link
Contributor Author

@benkiel, @typesupply, sorry for harping on this further, but it just occurred to me that we might be talking past each other a bit here.

By «optional» arguments, are we talking about predefined keyword arguments or optional types in the way typing.Optional regards them, as either any specified type or None?

@benkiel
Copy link
Member

benkiel commented Sep 26, 2024

@knutnergaard AH! Yes, I was talking about optional as predefined keyword args: ie, identifier=None is in _appendGuideline but not in appendGuideline, with is as intended from looking through the code (correct me if wrong @typesupply). I see you are referring to the **kwargs, which is unique to _appendGuideline and should be generically typed so environments can do whatever they need to there.

@knutnergaard
Copy link
Contributor Author

knutnergaard commented Sep 26, 2024

@benkiel Thanks, although when you say:

identifier=None is in _appendGuideline but not in appendGuideline

I assume you mean the other way around, i.e., that the public methods should have default arguments, but not the private ones?

@benkiel
Copy link
Member

benkiel commented Sep 26, 2024

Yes, you are correct, we should just have identifier in the private method, as the public method passes all values to the private one

@knutnergaard
Copy link
Contributor Author

@benkiel Removing the default values for certain methods breaks the code in a few places, at least in glyph.py. Particularly, _toMathGlyph or _fromMathGlyph, which are called elsewhere in the module without specific arguments presents problems when their defaults are removed. Should I just specify appropriate arguments whenever they're called in the code instead?

@benkiel
Copy link
Member

benkiel commented Sep 28, 2024

@knutnergaard Yes, we should do that, thank you!

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

No branches or pull requests

2 participants