How to avoid the error for a valid Python code on Pycharm












-3















This is my code:



from typing import Any, NamedTuple, Mapping, Optional
class Myclass(NamedTuple):
my_tenant_id: str
my_firstname_name: str
my_iphone_version: int
my_otherdetails: Optional[Mapping]


Python 3.6.6 says




Unresolved reference




at every line wherever : appears










share|improve this question




















  • 1





    Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

    – NEGR KITAEC
    Jan 3 at 8:14






  • 1





    please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

    – bruno desthuilliers
    Jan 3 at 8:15











  • I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

    – khangaroth
    Jan 3 at 8:28











  • from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

    – khangaroth
    Jan 3 at 8:29











  • I cannot reproduce your problem on 3.6.7.

    – DYZ
    Jan 3 at 8:59
















-3















This is my code:



from typing import Any, NamedTuple, Mapping, Optional
class Myclass(NamedTuple):
my_tenant_id: str
my_firstname_name: str
my_iphone_version: int
my_otherdetails: Optional[Mapping]


Python 3.6.6 says




Unresolved reference




at every line wherever : appears










share|improve this question




















  • 1





    Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

    – NEGR KITAEC
    Jan 3 at 8:14






  • 1





    please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

    – bruno desthuilliers
    Jan 3 at 8:15











  • I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

    – khangaroth
    Jan 3 at 8:28











  • from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

    – khangaroth
    Jan 3 at 8:29











  • I cannot reproduce your problem on 3.6.7.

    – DYZ
    Jan 3 at 8:59














-3












-3








-3








This is my code:



from typing import Any, NamedTuple, Mapping, Optional
class Myclass(NamedTuple):
my_tenant_id: str
my_firstname_name: str
my_iphone_version: int
my_otherdetails: Optional[Mapping]


Python 3.6.6 says




Unresolved reference




at every line wherever : appears










share|improve this question
















This is my code:



from typing import Any, NamedTuple, Mapping, Optional
class Myclass(NamedTuple):
my_tenant_id: str
my_firstname_name: str
my_iphone_version: int
my_otherdetails: Optional[Mapping]


Python 3.6.6 says




Unresolved reference




at every line wherever : appears







python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 8:28







khangaroth

















asked Jan 3 at 8:03









khangarothkhangaroth

188




188








  • 1





    Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

    – NEGR KITAEC
    Jan 3 at 8:14






  • 1





    please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

    – bruno desthuilliers
    Jan 3 at 8:15











  • I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

    – khangaroth
    Jan 3 at 8:28











  • from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

    – khangaroth
    Jan 3 at 8:29











  • I cannot reproduce your problem on 3.6.7.

    – DYZ
    Jan 3 at 8:59














  • 1





    Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

    – NEGR KITAEC
    Jan 3 at 8:14






  • 1





    please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

    – bruno desthuilliers
    Jan 3 at 8:15











  • I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

    – khangaroth
    Jan 3 at 8:28











  • from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

    – khangaroth
    Jan 3 at 8:29











  • I cannot reproduce your problem on 3.6.7.

    – DYZ
    Jan 3 at 8:59








1




1





Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

– NEGR KITAEC
Jan 3 at 8:14





Are you sure that you are using python 3.6.6? I had to set python3.6 in environment settings for it to work

– NEGR KITAEC
Jan 3 at 8:14




1




1





please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

– bruno desthuilliers
Jan 3 at 8:15





please post a proper MCVE - there's nothing named "NamedTuple" in the stdlib.

– bruno desthuilliers
Jan 3 at 8:15













I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

– khangaroth
Jan 3 at 8:28





I am using Python 3.6.6 as well as tried on 3.6.7 on Pycharm.It says Unresolved Reference despite me importing from typing import Any, NamedTuple, Mapping, Optional

– khangaroth
Jan 3 at 8:28













from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

– khangaroth
Jan 3 at 8:29





from typing import Any, NamedTuple, Mapping, Optional class Myclass(NamedTuple): my_tenant_id: str my_firstname_name: str my_iphone_version: int my_otherdetails: Optional[Mapping]

– khangaroth
Jan 3 at 8:29













I cannot reproduce your problem on 3.6.7.

– DYZ
Jan 3 at 8:59





I cannot reproduce your problem on 3.6.7.

– DYZ
Jan 3 at 8:59












1 Answer
1






active

oldest

votes


















0














If you wish to use type annotation, you'll have to assign the value as well.



my_tenant_id: str = ""
my_first_name: str = ""


python cannot predefine a variable without assigning values.



Update: It seems python's type annotation allows declaration of class variables without values.
https://docs.python.org/3/library/typing.html#typing.NamedTuple






share|improve this answer


























  • This is a class definition, not a variable definition. The posted code is valid.

    – DYZ
    Jan 3 at 8:17











  • Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

    – Thu Yein Tun
    Jan 3 at 8:22











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018413%2fhow-to-avoid-the-error-for-a-valid-python-code-on-pycharm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If you wish to use type annotation, you'll have to assign the value as well.



my_tenant_id: str = ""
my_first_name: str = ""


python cannot predefine a variable without assigning values.



Update: It seems python's type annotation allows declaration of class variables without values.
https://docs.python.org/3/library/typing.html#typing.NamedTuple






share|improve this answer


























  • This is a class definition, not a variable definition. The posted code is valid.

    – DYZ
    Jan 3 at 8:17











  • Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

    – Thu Yein Tun
    Jan 3 at 8:22
















0














If you wish to use type annotation, you'll have to assign the value as well.



my_tenant_id: str = ""
my_first_name: str = ""


python cannot predefine a variable without assigning values.



Update: It seems python's type annotation allows declaration of class variables without values.
https://docs.python.org/3/library/typing.html#typing.NamedTuple






share|improve this answer


























  • This is a class definition, not a variable definition. The posted code is valid.

    – DYZ
    Jan 3 at 8:17











  • Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

    – Thu Yein Tun
    Jan 3 at 8:22














0












0








0







If you wish to use type annotation, you'll have to assign the value as well.



my_tenant_id: str = ""
my_first_name: str = ""


python cannot predefine a variable without assigning values.



Update: It seems python's type annotation allows declaration of class variables without values.
https://docs.python.org/3/library/typing.html#typing.NamedTuple






share|improve this answer















If you wish to use type annotation, you'll have to assign the value as well.



my_tenant_id: str = ""
my_first_name: str = ""


python cannot predefine a variable without assigning values.



Update: It seems python's type annotation allows declaration of class variables without values.
https://docs.python.org/3/library/typing.html#typing.NamedTuple







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 8:26

























answered Jan 3 at 8:14









Thu Yein TunThu Yein Tun

593320




593320













  • This is a class definition, not a variable definition. The posted code is valid.

    – DYZ
    Jan 3 at 8:17











  • Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

    – Thu Yein Tun
    Jan 3 at 8:22



















  • This is a class definition, not a variable definition. The posted code is valid.

    – DYZ
    Jan 3 at 8:17











  • Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

    – Thu Yein Tun
    Jan 3 at 8:22

















This is a class definition, not a variable definition. The posted code is valid.

– DYZ
Jan 3 at 8:17





This is a class definition, not a variable definition. The posted code is valid.

– DYZ
Jan 3 at 8:17













Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

– Thu Yein Tun
Jan 3 at 8:22





Oh that is new for me. It seems you are correct. I read previously that pythons' type annotation is just for syntactic sugar. It doesn't add any new feature. But apparently in this case it does. Without : str python complains that the variable is undefined, but with : str it doesn't.

– Thu Yein Tun
Jan 3 at 8:22




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018413%2fhow-to-avoid-the-error-for-a-valid-python-code-on-pycharm%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas