{"record":{"id":"866c75b4461e2700","repo":"locustio/locust","slug":"deprecation-message-e-g-the-locust-class-has-bee","errorCode":null,"errorMessage":"deprecation_message (e.g. The Locust class has been renamed to User in version 1.0. Use User instead)","messagePattern":"deprecation_message \\(e\\.g\\. The Locust class has been renamed to User in version 1\\.0\\. Use User instead\\)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"locust/util/deprecation.py","lineNumber":26,"sourceCode":"    from locust.user.task import TaskSet\n\n    if \"task_set\" in class_dict:\n        task_set = class_dict[\"task_set\"]\n        if issubclass(task_set, TaskSet) and not hasattr(task_set, \"locust_task_weight\"):\n            warnings.warn(\n                \"Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead \"\n                f\"(tasks = [{task_set.__name__}])\",\n                DeprecationWarning,\n            )\n\n\ndef deprecated_locust_meta_class(deprecation_message):\n    class MetaClass(type):\n        def __new__(mcs, classname, bases, class_dict):\n            if classname in [\"DeprecatedLocustClass\", \"DeprecatedHttpLocustClass\", \"DeprecatedFastHttpLocustClass\"]:\n                return super().__new__(mcs, classname, bases, class_dict)\n            else:\n                raise ImportError(deprecation_message)\n\n    return MetaClass\n\n\n# PEP 484 specifies \"Generic metaclasses are not supported\", see https://github.com/python/mypy/issues/3602, ignore typing errors\nclass DeprecatedLocustClass(\n    metaclass=deprecated_locust_meta_class(  # type: ignore\n        \"The Locust class has been renamed to User in version 1.0. \"\n        \"For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0\"\n    )\n):\n    pass\n\n\nclass DeprecatedHttpLocustClass(\n    metaclass=deprecated_locust_meta_class(  # type: ignore\n        \"The HttpLocust class has been renamed to HttpUser in version 1.0. \"\n        \"For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0\"","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/util/deprecation.py#L8-L44","documentation":"deprecated_locust_meta_class builds a metaclass that allows only its internal placeholder classes to be created; any subclass of a deprecated Locust/HttpLocust alias raises ImportError with the supplied deprecation message.","triggerScenarios":"Subclassing locust.Locust, HttpLocust, or FastHttpLocust aliases from locust.util.deprecation (pre-1.0 names) after the 1.0 rename.","commonSituations":"Old locustfiles upgraded to Locust 1.0+ still using `class MyLocust(Locust)` or `HttpLocust`; tutorials predating the rename.","solutions":["Rename base class from Locust to User","Rename HttpLocust to HttpUser","Rename FastHttpLocust to FastHttpUser","Update imports to the new names from locust"],"exampleFix":"// before\nfrom locust import HttpLocust, TaskSet\nclass MyLocust(HttpLocust):\n    ...\n// after\nfrom locust import HttpUser, task, between\nclass MyUser(HttpUser):\n    ...","handlingStrategy":"validation","validationCode":"assert not issubclass(MyUser, tuple(b for b in MyUser.__mro__ if getattr(getattr(b, '__class__', None), '__name__', '') == 'MetaClass' or b.__name__ in ('Locust','HttpLocust','FastHttpLocust'))), \"Use User/HttpUser instead of deprecated names\"","typeGuard":null,"tryCatchPattern":"try:\n    class MyLocust(HttpLocust): ...\nexcept ImportError as e:\n    logging.error(\"Rename to HttpUser: %s\", e)","preventionTips":["Use User/HttpUser/FastHttpUser in all new code","Run a 1.0+ migration check on old locustfiles"],"tags":["python","locust","deprecation","migration","import"],"backgroundTag":"deprecated-class-rename","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}