rambleraptor commented on code in PR #3934:
URL: https://github.com/apache/iceberg-python/pull/3934#discussion_r3992446154


##########
pyiceberg/cli/console.py:
##########
@@ -142,38 +143,61 @@ def list(ctx: Context, parent: str | None) -> None:  # 
pylint: disable=redefined
 
 
 @run.command()
[email protected]("--entity", type=click.Choice(["any", "namespace", "table"]), 
default="any")
[email protected](
+    "--entity",
+    type=click.Choice(["any", "namespace", "table"]),
+    default="any",
+    help="Entity type. 'any' auto-detects and requires --entity when 
ambiguous.",
+)
 @click.argument("identifier")
 @click.pass_context
 @catch_exception()
-def describe(ctx: Context, entity: Literal["name", "namespace", "table"], 
identifier: str) -> None:
+def describe(ctx: Context, entity: Literal["any", "namespace", "table"], 
identifier: str) -> None:
     """Describe a namespace or a table."""
     catalog, output = _catalog_and_output(ctx)
     identifier_tuple = Catalog.identifier_to_tuple(identifier)
 
-    is_namespace = False
-    if entity in {"namespace", "any"} and len(identifier_tuple) > 0:
-        try:
-            namespace_properties = 
catalog.load_namespace_properties(identifier_tuple)
-            output.describe_properties(namespace_properties)
-            is_namespace = True
-        except NoSuchNamespaceError as exc:
-            if entity != "any" or len(identifier_tuple) == 1:  # type: ignore
-                raise exc
-
-    is_table = False
-    if entity in {"table", "any"} and len(identifier_tuple) > 1:
-        try:
-            catalog_table = catalog.load_table(identifier)
-            output.describe_table(catalog_table)
-            is_table = True
-        except NoSuchTableError as exc:
-            if entity != "any":
-                raise exc
-
-    if is_namespace is False and is_table is False:
+    if entity == "namespace":
+        
output.describe_properties(catalog.load_namespace_properties(identifier_tuple))
+        return
+    if entity == "table":
+        output.describe_table(catalog.load_table(identifier))
+        return
+
+    if len(identifier_tuple) == 1:
+        
output.describe_properties(catalog.load_namespace_properties(identifier_tuple))
+        return
+
+    matches: tuple[str, ...] = ()
+    namespace_properties: Properties | None = None
+    catalog_table: Table | None = None
+
+    try:

Review Comment:
   nit: comment here describing that this is a namespace attempt could be good.



##########
pyiceberg/cli/console.py:
##########
@@ -142,38 +143,61 @@ def list(ctx: Context, parent: str | None) -> None:  # 
pylint: disable=redefined
 
 
 @run.command()
[email protected]("--entity", type=click.Choice(["any", "namespace", "table"]), 
default="any")
[email protected](
+    "--entity",
+    type=click.Choice(["any", "namespace", "table"]),
+    default="any",
+    help="Entity type. 'any' auto-detects and requires --entity when 
ambiguous.",
+)
 @click.argument("identifier")
 @click.pass_context
 @catch_exception()
-def describe(ctx: Context, entity: Literal["name", "namespace", "table"], 
identifier: str) -> None:
+def describe(ctx: Context, entity: Literal["any", "namespace", "table"], 
identifier: str) -> None:
     """Describe a namespace or a table."""
     catalog, output = _catalog_and_output(ctx)
     identifier_tuple = Catalog.identifier_to_tuple(identifier)
 
-    is_namespace = False
-    if entity in {"namespace", "any"} and len(identifier_tuple) > 0:
-        try:
-            namespace_properties = 
catalog.load_namespace_properties(identifier_tuple)
-            output.describe_properties(namespace_properties)
-            is_namespace = True
-        except NoSuchNamespaceError as exc:
-            if entity != "any" or len(identifier_tuple) == 1:  # type: ignore
-                raise exc
-
-    is_table = False
-    if entity in {"table", "any"} and len(identifier_tuple) > 1:
-        try:
-            catalog_table = catalog.load_table(identifier)
-            output.describe_table(catalog_table)
-            is_table = True
-        except NoSuchTableError as exc:
-            if entity != "any":
-                raise exc
-
-    if is_namespace is False and is_table is False:
+    if entity == "namespace":
+        
output.describe_properties(catalog.load_namespace_properties(identifier_tuple))
+        return
+    if entity == "table":
+        output.describe_table(catalog.load_table(identifier))
+        return
+
+    if len(identifier_tuple) == 1:
+        
output.describe_properties(catalog.load_namespace_properties(identifier_tuple))
+        return
+
+    matches: tuple[str, ...] = ()
+    namespace_properties: Properties | None = None
+    catalog_table: Table | None = None
+
+    try:
+        namespace_properties = 
catalog.load_namespace_properties(identifier_tuple)
+        matches += ("namespace",)
+    except NoSuchNamespaceError:
+        pass
+
+    try:

Review Comment:
   same as above but with table



##########
pyiceberg/cli/console.py:
##########
@@ -142,38 +143,61 @@ def list(ctx: Context, parent: str | None) -> None:  # 
pylint: disable=redefined
 
 
 @run.command()
[email protected]("--entity", type=click.Choice(["any", "namespace", "table"]), 
default="any")
[email protected](
+    "--entity",
+    type=click.Choice(["any", "namespace", "table"]),
+    default="any",
+    help="Entity type. 'any' auto-detects and requires --entity when 
ambiguous.",
+)
 @click.argument("identifier")
 @click.pass_context
 @catch_exception()
-def describe(ctx: Context, entity: Literal["name", "namespace", "table"], 
identifier: str) -> None:
+def describe(ctx: Context, entity: Literal["any", "namespace", "table"], 
identifier: str) -> None:
     """Describe a namespace or a table."""
     catalog, output = _catalog_and_output(ctx)
     identifier_tuple = Catalog.identifier_to_tuple(identifier)
 
-    is_namespace = False
-    if entity in {"namespace", "any"} and len(identifier_tuple) > 0:
-        try:
-            namespace_properties = 
catalog.load_namespace_properties(identifier_tuple)
-            output.describe_properties(namespace_properties)
-            is_namespace = True
-        except NoSuchNamespaceError as exc:
-            if entity != "any" or len(identifier_tuple) == 1:  # type: ignore
-                raise exc
-
-    is_table = False
-    if entity in {"table", "any"} and len(identifier_tuple) > 1:
-        try:
-            catalog_table = catalog.load_table(identifier)
-            output.describe_table(catalog_table)
-            is_table = True
-        except NoSuchTableError as exc:
-            if entity != "any":
-                raise exc
-
-    if is_namespace is False and is_table is False:
+    if entity == "namespace":

Review Comment:
   ```suggestion
       if entity == "namespace" or (entity == "any" and len(identifier_tuple) 
== 1):
   ```
   This will clean up the if statement at line 167, but it's a bit harder to 
parse. Your call.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to