You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python LSP Server (pylsp) with jedi is producing false positive type warnings when working with the productmd library, incorrectly inferring types as Unknown | None when the actual runtime type is str or dict.
pylsp/jedi is attempting to infer types from runtime behavior but is incorrectly determining that certain attributes could be None when they are guaranteed to be specific types after initialization.
Issue 1: False Positive on ComposeInfo.compose.id
LSP Warning
ERROR [312:29] Argument of type "Unknown | None" cannot be assigned to parameter "compose_id" of type "str" in function "print_summary"
Type "Unknown | None" is not assignable to type "str"
"None" is not assignable to "str"
Code
fromproductmd.composeinfoimportComposeInfodefcreate_compose_info(args) ->ComposeInfo:
ci=ComposeInfo()
ci.release.name=args.release_nameci.release.short=args.release_shortci.release.version=args.release_versionci.release.type=args.release_typeci.release.is_layered=args.release_is_layeredci.compose.date=args.compose_dateci.compose.type=args.compose_typeci.compose.respin=args.compose_respinifargs.compose_label:
ci.compose.label=args.compose_labelci.compose.id=ci.create_compose_id() # This returns strreturncidefprint_summary(args, compose_id: str) ->None:
# ... implementation ...passdefmain() ->int:
args=parse_args()
compose_info=create_compose_info(args)
compose_id=compose_info.compose.id# LSP thinks this is Unknown | None# LSP ERROR: compose_id inferred as Unknown | None, but it's actually strprint_summary(args, compose_id) # <-- False positive warning here
Actual Runtime Behavior
>>>fromproductmd.composeinfoimportComposeInfo>>>ci=ComposeInfo()
>>>ci.compose.idNone# Before calling create_compose_id()>>>ci.release.name="Test">>>ci.release.short="TEST">>>ci.release.version="1.0">>>ci.release.type="ga">>>ci.compose.date="20260311">>>ci.compose.type="production">>>ci.compose.respin=0>>>ci.compose.id=ci.create_compose_id()
>>> type(ci.compose.id)
<class'str'>>>>ci.compose.id'TEST-1.0-20260311.0'
Expected: After calling ci.create_compose_id() and assigning it to ci.compose.id, the type should be inferred as str, not Unknown | None.
Actual: pylsp/jedi infers the type as Unknown | None because ci.compose.id starts as None before initialization.
Issue 2: False Positive on VariantPaths Dictionary Attributes
LSP Warnings
ERROR [68:35] Cannot access attribute "repository" for class "VariantPaths"
Attribute "repository" is unknown
ERROR [74:35] Cannot access attribute "debug_repository" for class "VariantPaths"
Attribute "debug_repository" is unknown
ERROR [80:31] Cannot access attribute "source_repository" for class "VariantPaths"
Attribute "source_repository" is unknown
Caution
AI generated report follows
Summary
Python LSP Server (pylsp) with jedi is producing false positive type warnings when working with the
productmdlibrary, incorrectly inferring types asUnknown | Nonewhen the actual runtime type isstrordict.Environment
b719ac380fa94a3c68093479957d3ae1aab75c6b)Root Cause
The
productmdlibrary has no type annotations:py.typedmarker file.pyistub files__annotations__on classespylsp/jedi is attempting to infer types from runtime behavior but is incorrectly determining that certain attributes could be
Nonewhen they are guaranteed to be specific types after initialization.Issue 1: False Positive on
ComposeInfo.compose.idLSP Warning
Code
Actual Runtime Behavior
Expected: After calling
ci.create_compose_id()and assigning it toci.compose.id, the type should be inferred asstr, notUnknown | None.Actual: pylsp/jedi infers the type as
Unknown | Nonebecauseci.compose.idstarts asNonebefore initialization.Issue 2: False Positive on
VariantPathsDictionary AttributesLSP Warnings
Code
Actual Runtime Behavior
Expected: pylsp/jedi should recognize that
VariantPathshasrepository,debug_repository, andsource_repositoryattributes that are dictionaries.Actual: pylsp/jedi claims these attributes don't exist on
VariantPathsclass, despite them being present and functioning correctly at runtime.Impact
These false positive warnings:
Reproduction Case
Additional Context
These issues are not caused by the modification in the development branch, the same problems are most likely happening on master too.