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

REL: set version to 0.5.0 #77

Merged
merged 2 commits into from
Jan 3, 2025
Merged

Conversation

lucascolley
Copy link
Collaborator

No description provided.

@lucascolley
Copy link
Collaborator Author

@jorenham @KotlinIsland I am seeing some error: "object" not callable [operator] errors for objects which I'm pretty sure are in fact callable. This is with basedmypy 2.9.0. Any ideas?

@lucascolley
Copy link
Collaborator Author

basedpyright reports no failures

@lucascolley
Copy link
Collaborator Author

baedmypy 2.8.1 reports no failures

@lucascolley
Copy link
Collaborator Author

I'll probably just pin basedmypy for this release, we can figure out what's going on after that

@lucascolley lucascolley merged commit c7b47f1 into data-apis:main Jan 3, 2025
10 checks passed
@lucascolley lucascolley deleted the release branch January 3, 2025 13:50
@lucascolley lucascolley mentioned this pull request Jan 3, 2025
@jorenham
Copy link

jorenham commented Jan 3, 2025

I believe this has to do with @KotlinIsland 's change in the bundled typeshed so that builtins.getattr now returns object instead of Any

@KotlinIsland
Copy link

perhaps we could introduce a no_strict_stdlib config option to basedmypy? from experience these stricter types are very beneficial, but I understand that it doesn't fit every usecase

@lucascolley
Copy link
Collaborator Author

it may well be that we are relying on some undefined behaviour, or have incorrectly typed something, so I'd rather check that before changing the config

@KotlinIsland
Copy link

the issue is that the behavior of getting attrs is underspecified within the typesystem, even for the most trivial of cases:

class A:
    a = 1
getattr(A, 'a')  # Any

@jorenham
Copy link

jorenham commented Jan 3, 2025

the issue is that the behavior of getting attrs is underspecified within the typesystem, even for the most trivial of cases:

class A:
    a = 1
getattr(A, 'a')  # Any

It also can't even do this:

class A:
    def __getattr__(self, attr: str, /) -> int:
        return 42
a = A()
reveal_type(getattr(a, "any"))  # Type of "getattr(a, "any")" is "Any"

@lucascolley
Copy link
Collaborator Author

right, so what would be the advisable way to deal with this downstream? type: ignore comments? Change a config setting? add some extra annotations?

@jorenham
Copy link

jorenham commented Jan 3, 2025

right, so what would be the advisable way to deal with this downstream? type: ignore comments? Change a config setting? add some extra annotations?

typing.cast would be the cleanest in this situation I think.


because Any is basically an object that automatically casts itself to whatever it's being assigned to

@lucascolley
Copy link
Collaborator Author

PR welcome I guess 😉 (no pressure)

@KotlinIsland
Copy link

KotlinIsland commented Jan 3, 2025

sorry, what is your preferred action here?

right, so what would be the advisable way to deal with this downstream?

if by downstream you are refering to this project, then i recommend writing your own getattr function that is explicitly typed to return Any. the motivation for this change originally was "the behavior of getattr should be typed by default, if you want it as Any then implement that yourself"

an alternative, that is more safe would be to cast each and every attr that is gotten to the expected type. i prefer this approach as it is more descriptive and type safe than using Any:

name = cast(str, getattr(entity, "name"))

@lucascolley
Copy link
Collaborator Author

the cast approach looks fine to me!

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