#Copilot issues

1 messages · Page 1 of 1 (latest)

real musk
#

https://github.com/home-assistant/core/pull/165259#discussion_r2910626828

Bug: Python 3.13 and earlier syntax error in except clause. except ValueError, TypeError: is the old Python 2 syntax (which Python 3.14 re-allows as except TypeA, TypeB:). However, even in Python 3.14 where this syntax is valid, except ValueError, TypeError: catches ValueError and binds the exception to the name TypeError, shadowing the built-in TypeError. The intended behavior is to catch both exception types, which requires parentheses: except (ValueError, TypeError):. This means TypeError exceptions will not be caught, and the TypeError built-in will be shadowed in the except block.

#
## Python Syntax Notes

- Python 3.14 explicitly allows `except TypeA, TypeB:` without parentheses.
muted stone
#

We can improve the copilot instructions

#

but memory can also pick it up if we leave a comment on those

real musk
#

Do I just comment or also ping copilot

muted stone
#

Mentioning Copilot will cause it to take action (and thus make a PR); so that doesn't seem the right path

#

Looking at the memory, there is actually a conflicting memory in there

#

Let me clean up the first one

past cypress
#

is it possible to enable access to copilot memory for non-admins of the repo? even read-only would be fine

real musk
#

I'm also wondering if we can turn copilot off for Syntax things

latent cradle
dapper turret
#

It seems to be confused also by missing from __future__ import annotations

SpotifyData uses SpotifyCoordinator and SpotifyDeviceCoordinator in annotations before those classes are defined, but this module does not use postponed evaluation of annotations. This will raise a NameError at import time when defining SpotifyData. Add from future import annotations at the top of this module (consistent with other spotify files) or quote these annotations (e.g., "SpotifyCoordinator").

I think these are no longer necessary for 3.14

surreal furnace
#

why not? 3.14 did not complete the transition to the new type annotations?

#

I mean, there's https://peps.python.org/pep-0749/, but does that mean we can now delete all from __future__ import annotations? If yes, we should do that across the board and add a custom rule disallowing it for consistency.

dapper turret
#

They are almost always unnecessary now - but they are not 100% no-op
My suggestion is only to avoid in new code and avoid copilot requesting it for now

surreal furnace
#

Have you tried removing them all?

#

Some container class libraries are messing with type annotations IIRC, are those affected?

muted stone
muted stone
dapper turret
surreal furnace
#

OK. Can you improve the PR description a bit? Maybe explain the implementation of PEP 649 in Python 3.14 means it's no longer needed for forward references (that's essentially why we used it AFAIK)? Maybe link to PEP 749?

dapper turret
surreal furnace
#

I don't understand what you mean

#

The major benefit offrom __future__ import annotations is that it allows forward references in type annotations

#

It doesn't change anything wrt to other forward references, that's still limited by some misguided design choices when Python was first created

dapper turret
#

It seems that entity.py is impacted because of annotations = cls.__annotations__

surreal furnace
#

OK. We should ban the idiot who added that

#

It's the same person who implemented the FrozenOrThawed horror, which ALSO is messing with annotations

#

Damn it

#

I think both of those hacks were influenced by the stdlib implementation of dataclasses, but I could be mistaken

#

If they are, maybe the dataclasses implementation in 3.14 is updated

dapper turret
#

Anyway - we are drifting from the original "copilot" thread.
I think copilot should stop "recommending" adding from __future__ import annotations
There are a few places where it is still needed - but not many and shouldn't be a blanket recommendation

dapper turret
surreal furnace
#

I'd rather it always recommend it for consistency. Until the unittest issue is fixed.

dapper turret
surreal furnace
#

I closed it with a link to the CPython issue

surreal furnace
#

The bot is recently trying to act more and more like a linter, which it fails spectacularly at. Did you try improving the instructions @real musk ?

#

Yesterday it claimed the linter would probably force line breaks because a line was probably too long. This is a waste of energy for everyone.

#

It's also been complaining about mypy probably not liking something, I've seen many BS complaints about type narrowing.