Skip to content

POC: appease linter for gh-53 #59

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

Closed
wants to merge 6 commits into from

Conversation

lucascolley
Copy link
Member

Looks like there are no unresolvable or essential conflicts here, just required a little bit of wrangling :)

@jorenham would you be able to review the typing? I've added a few Any aliases where I wasn't sure how to annotate.

@crusaderky once we check that the linter is happy here, shall I make a PR to your branch? Then you can continue your work in gh-53.

@lucascolley lucascolley mentioned this pull request Dec 10, 2024
Comment on lines 714 to 718
elif copy is None: # type: ignore[redundant-expr]
writeable = is_writeable_array(x)
copy = _is_update and not writeable
else:
msg = f"Invalid value for copy: {copy!r}" # type: ignore[unreachable] # pyright: ignore[reportUnreachable]
Copy link
Member Author

Choose a reason for hiding this comment

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

is there a better way to deal with situations like this where invalid types can be passed at runtime?

Copy link
Contributor

Choose a reason for hiding this comment

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

This double-ignore is a strong example of why I'm strongly in favour of having only one type checker. This is tedious to both read and write.

Choose a reason for hiding this comment

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

it's definitely annoying, but unfortunately it's the only possibility for ensuring compatibility with these two main type-checkers

Choose a reason for hiding this comment

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

but I agree with mypy and pyright that the else clause here is redundant

Copy link

@jorenham jorenham Dec 10, 2024

Choose a reason for hiding this comment

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

you could alternatively move the if copy is None to the top, and then do elif copy: ... else: .... That way you'd also allow e.g. 0, 1, and the np.bool_ values (at runtime)

Copy link
Member Author

@lucascolley lucascolley Dec 10, 2024

Choose a reason for hiding this comment

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

what if we still want to throw an error at runtime if copy="foo" is passed? I guess the argument is that, since this is internal, that would always be caught by the static analysis anyway?

EDIT: ah, it isn't internal, since the methods pass**kwargs through. I suppose this can be resolved once the methods are given explicit copy and xp kwargs

@lucascolley
Copy link
Member Author

broadly, I agree on not going overkill on the types. Let's just get something in that works.


x: Array
idx: Index
__slots__: ClassVar[tuple[str, str]] = ("idx", "x")
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO the linter should not force me to define the type of __slots__, because it's part of the python data model. This only adds attrition and reduces readability.

Choose a reason for hiding this comment

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

I agree

Copy link
Member Author

@lucascolley lucascolley Dec 10, 2024

Choose a reason for hiding this comment

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

looks like this is no longer needed

EDIT: only if at is made final

@crusaderky
Copy link
Contributor

@crusaderky once we check that the linter is happy here, shall I make a PR to your branch?

No need I can cherry-pick

@lucascolley
Copy link
Member Author

Feel free to cherry-pick from this point @crusaderky and we can continue in your PR

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.

3 participants