Python Forum
"Class already defined" while using typings.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Class already defined" while using typings.
I'm building a little program but I'm trying to make it more easily expandable for the future (without the need of much refactoring). I'm experimenting with thing I have never used before like typings.
I have a small typings file that looks like this (called
from typing import (

from typing import ForwardRef as ref

CustomLevel = ref("levels.level.CustomLevel")
OfficialLevel = ref("levels.level.OfficialLevel")

__all__ = (

I also have a file under ./levels/. In the file I have a base class but also a CustomLevel and OfficialLevel. At the top of I am importing the CustomLevel typing. The issue is I am getting an error saying:
class already defined (line 5)
because the import of the CustomLevel type is clashing with definition of the CustomLevel class, like so:
from ..typings import (

class CustomLevel(): #<--- erros here since 'customlevel' is already defined
	def __init__(self) -> None:
	def somefunc(self) -> CustomLevel:
I am actually using an already existing api as a sort of "guide". What I mean is I am looking at the code of the api, because I think it's pretty good code, and using some of the features I think will be helpful in my program (like typings). In their api they do exactly what I am doing where they import a type from their typing file, and then create a class of the same name. In theirs they don't get an error though.

How can I fix this error?

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why built in functions are defined as class? quazirfan 5 331 Yesterday, 01:20 PM
Last Post: Gribouillis
  Error when refering to class defined in 'main' in an imported module HeRo 2 709 Apr-13-2021, 07:22 PM
Last Post: HeRo
  python library not defined in user defined function johnEmScott 2 993 May-30-2020, 04:14 AM
Last Post: DT2000
  Python complains that class instance is not defined colt 3 1,677 Sep-17-2019, 12:32 AM
Last Post: ichabod801
  saving (in text or binary) an object under a defined class cai0824 3 1,465 May-12-2019, 08:55 AM
Last Post: snippsat
  "not defined" error in function referencing a class Exsul 2 1,992 Mar-27-2019, 11:59 PM
Last Post: Exsul
  Creating class - name not defined error python_alex 3 6,781 Jun-30-2018, 11:17 PM
Last Post: snippsat
  name a thread defined from a class ricardons 1 1,393 Mar-10-2018, 10:59 PM
Last Post: ricardons

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020