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

py.typed and strictly type-checked #3

Merged
merged 2 commits into from
Aug 29, 2024
Merged

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Aug 25, 2024

Ref: jaraco/skeleton#143

Such a small repo, it was basically already there.

Comment on lines 47 to 54
if sys.version_info < (3, 9): # pragma: no cover
cache = functools.lru_cache(maxsize=None)
r_fix = _fixer
else:
cache = functools.cache

cache = (
functools.cache # type: ignore[attr-defined]
if sys.version_info >= (3, 9)
else functools.lru_cache(maxsize=None)
)
def r_fix(orig: str) -> str:
return orig
Copy link
Owner

Choose a reason for hiding this comment

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

I do prefer to have single assignment rather than conditional assignment. I also like to keep concerns separate. With this change, now r_fix and cache is interleaved.

But I see now why you do it - mypy doesn't honor conditionals that aren't conditional blocks.

The problem with accepting this change is I'm already tempted to refactor it to separate the concerns and consolidate assignments.

I think this is a case where the value of the original logic is greater than the value of the type checking.

Restored in 67d3f31.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's definitely a balance of what you value!
Pyright understands "ternary" (conditional expression), by not mypy https://github.com/python/mypy/issues?q=sort%3Aupdated-desc+is%3Aopen+label%3Atopic-ternary-expression (the most specific issue/request related to this case would be python/mypy#13003 )

Generally as long as the exposed type is correct.

@jaraco jaraco merged commit c9d7a22 into jaraco:main Aug 29, 2024
12 checks passed
@Avasam Avasam deleted the Strictly-typed branch August 29, 2024 16:02
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